<?php

class Ext_Avatar_Show
{
    public $big;
    public $middle;
    public $small;
    public $thumb;
    
    public function __construct($userId)
    {
        $this->_build($userId);
    }
    
    private function _build($userId)
    {
        if(!$userId){
            $this->_setDefaultUrl();
            return "";
        }
        
        $userAvatarRow = App_Model_DbTable_User_Avatar::getInstance()->getRowByUserId($userId);
        if(!$userAvatarRow){
            $this->_setDefaultUrl();
            return "";
        }
        if(!isset($userAvatarRow['avatarId'])){
            $this->_setDefaultUrl();
            return "";
        }
        $avatarId = $userAvatarRow['avatarId'];
        
        $adapter = new Ext_Avatar_Show_Adapter();
        $adapter->build($avatarId);
        
        $this->big    = $adapter->big;
        $this->middle = $adapter->middle;
        $this->small  = $adapter->small;
        $this->thumb  = $adapter->thumb;
    }
    
    private function _setDefaultUrl()
    {
        $config = Ext_Config::getInstance()->getConfig('image');
        $settings = Zend_Registry::get('settings');
        
        $front = Zend_Controller_Front::getInstance();
        $bootstrap = $front->getParam('bootstrap');
        $view = $bootstrap->getResource('view');
        $url = $view->baseUrl();
        
        $_avatars = array('big', 'middle', 'small', 'thumb');
        for($i=0;$i<count($_avatars);$i++){
            $_avatar = $_avatars[$i];
            $width = $config->avatar->size->{$_avatar};
            
            $this->{$_avatar} = rtrim($url, "/") . "/ui/style/base/".$settings['styleBase']."/images/avatar/" . $width . ".jpg";
        }
    }

}
